package com.lingshu.app.ui.message;

import androidx.lifecycle.MutableLiveData;

import com.lingshu.app.base.BaseViewModel;
import com.lingshu.app.database.bean.MessageBean;
import com.lingshu.app.repository.MessageRepository;

import java.util.List;

import javax.inject.Inject;

import dagger.hilt.android.lifecycle.HiltViewModel;

/**
 * @author 于定金
 * @version 1.0
 * @Date 2024/1/3 14:15
 * @Description
 */
@HiltViewModel
public class MessageFragmentViewModel extends BaseViewModel {

    private static final String TAG = MessageFragmentViewModel.class.getSimpleName();

    MessageRepository messageRepository;

    @Inject
    MessageFragmentViewModel(MessageRepository messageRepository) {
        this.messageRepository = messageRepository;
    }

    /**
     * 数据初始化
     */
    @Override
    public void initData() {
        messageRepository.getCount();
    }

    public MutableLiveData<List<MessageBean>> getMessageList(int pageSize, int offset) {
        return messageRepository.getPagedList(pageSize, offset);
    }

    public void updateMessage(MessageBean messageBean) {
        messageRepository.updateMessages(messageBean);
    }

    public void add() {
        MessageBean message = new MessageBean(1, 25L, "dfdsfsdfsadfsa", false, System.currentTimeMillis());
        messageRepository.saveMessages(message);
    }

    public void update() {
        messageRepository.getMessage(1);
    }

    public void query() {
        messageRepository.getCount();
    }
}
